package org.geektimes.projects.user.jmx.ioc;

import com.alibaba.fastjson.JSONObject;
import org.geekbang.projects.injection.ApplicationContext;
import org.geekbang.projects.injection.jmx.MBeanRegister;
import org.geekbang.projects.injection.processor.ApplicationContextAware;

import static org.geektimes.projects.user.jmx.ioc.IocContextManager.DOMAIN;

/**
* ioc上下文监控管理  
* @author : lsq
*/
@MBeanRegister(domain = DOMAIN)
public class IocContextManager implements IocContextManagerMBean , ApplicationContextAware {


	public static final String DOMAIN = "org.geektimes.projects.user.web:type=IOC";

	private ApplicationContext applicationContext;


	@Override
	public int getBeanCount() {
		return applicationContext.getBeanNames().size();
	}


	@Override
	public String toBeansString() {
		return JSONObject.toJSONString(applicationContext.getBeanNames());
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
	}
}
